<template>
	<view class="pics">
		<scroll-view class="left" scroll-y>
			<view :class="active===index?'active':''" v-for="(item,index) in cates" :key="item.id" @click="leftHandClick(index,item.id)">{{item.title}}</view>
		</scroll-view>
		<scroll-view class="right" scroll-y>
			<view class="item" v-for="item in secondData">
				<image :src="item.img_url" @click="previewImage(item.img_url)"></image>
				<text>{{item.title}}</text>
			</view>
			<text class='tips' v-if="secondData.length==0">暂无数据</text>
		</scroll-view>
	</view>
</template>
<script>
	export default{
		data(){
			return{
				cates:[],
				active:0,
				secondData:[]
			}
		},
		onLoad() {
			this.getPicsCate();
		},
		methods:{
			async getPicsCate(){
				const res = await this.$myRequest({
					url:"/api/getimgcategory"
				})
				console.log(res);
				this.cates = res.data.message;
				this.leftHandClick(0)
			},
			async leftHandClick(index,id){
				this.active = index;
				//获取右侧的数据
				const res = await this.$myRequest({
					url:"/api/getimages/"+id
				})
				this.secondData = res.data.message;
			},
			previewImage(current){
				const urls = this.secondData.map(item=>{
					return item.img_url;
				})
				uni.previewImage({
					urls,
					current
				})
			}
		}
	}
</script>

<style>
	page{
		width:100%;
		height:100%;
	}
	.pics{
		height:100%;
		display:flex;
	}
	.pics .left{
		width:200rpx;
		height:100%;
		border-right:1px solid #ededed;
	}
	
	.pics .left view{
		height:60px;
		line-height:60px;
		font-size:30rpx;
		color:#333;
		text-align:center;
		border-top:1px solid #ededed;
	}
	.pics .left view:first-child{
		border-color:#fff;
	}
	.pics .left .active{
		background:#b50e03;
		color:#fff;
	}
	.pics .right{
		height:100%;
		width:550rpx;
		
	}
	.pics .right .item{
		width:530rpx;
		height:530rpx;
		margin:0 auto;
		border-radius:5px;
	}
	.pics .right text{
		font-size:30rpx;
		line-height:50rpx;
	}
	.pics .right .tips{
		display:block;
		width:100%;
		text-align:center;
		margin:10px auto;
	}
</style>